<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('渠道统计列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: daterangepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>渠道编号：</label>
                                <input type="text" name="channelCode" autocomplete="off"/>
                            </li>
                            <li>
                                <label>渠道名称：</label>
                                <select name="channelCode"
                                        data-none-selected-text="123"
                                        data-height="600"
                                        class="form-control select2-multiple"
                                        data-dismiss="false" style="height: 600px"
                                        multiple="multiple" data-live-search="true" windows>
                                    <option  th:each="item:${channelInfoList}" th:text="${item.name}" th:value="${item.value}" ></option>
                                </select>
                            </li>

                            <li>
                                <label>渠道商务：</label>
                                <div class="col-sm-2">
                                    <select class="form-control" name="ownerId">
                                        <option value="">所有</option>
                                        <option th:each="item:${managerInfoList}" th:value="${item.userId}"
                                                th:text="${item.username}"></option>
                                    </select>
                                </div>
                            </li>

                            <li>
                                <label>渠道类型：</label>
                                <select name="channelType" class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${channelTypeList}" th:text="${item.name}" th:value="${item.value}" ></option>
                                </select>
                            </li>

                            <li>
                                <label>日期：</label>
                                <input type="text" name="dateInfo" id="dateInfo" autocomplete="off"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class=" table-hover"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: daterangepicker-js" />
     <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">

        var editFlag = [[${@permission.hasPermi('extend:count:edit')}]];
        var removeFlag = [[${@permission.hasPermi('extend:count:remove')}]];
        var prefix = ctx + "extend/count";
        var prefixView = ctx + "extend/countview/";

        $(function() {
            var options = {
                id:"bootstrap-table",
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                modalName: "渠道统计",
                striped: false,
                // rowStyle: function (row, index) {
                //     return {classes:'table_row'}
                // },
                columns: [
                //     {
                //     checkbox: true
                // },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'dateInfo',
                    title: '日期'
                },
                {
                    field: 'channelName',
                    title: '渠道名称',
                    formatter: function (value,row,index){

                        var result = '';
                        if (row.channelName == undefined){
                            result = '-';
                        }else{
                            if (row.channelType == 'DC'){
                                result = '<span style="color: #1c84c6; border-bottom: 1px solid " onclick="channelInfoView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.channelName+'</a>';
                            }else if (row.channelType == 'ZD'){
                                result = '<span style="color: #c90e46; border-bottom: 1px solid " onclick="channelInfoView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.channelName+'</a>';
                            }else{
                                result = '<span style=" border-bottom: 1px solid " onclick="channelInfoView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.channelName+'</a>';
                            }
                            result = result + '(' + row.channelPrice +')';
                        }
                        return result;
                    }
                },
                {
                    field: 'uvCount',
                    title: 'uv数量',
                    formatter: function (value,row,index){
                        var result = (row.channelCode == undefined)?row.uvCount:'<span style="color: #1c84c6; border-bottom: 1px solid" onclick="uvCountView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.uvCount+'</a>';
                        return result;
                    }
                },
                {
                    field: 'uvCost',
                    title: 'uv成本'
                },
                {
                    field: 'registerCount',
                    title: '注册数量',
                    formatter: function (value, row, index){
                        return row.registerCountReal == undefined?row.registerCount:row.registerCount+' ('+ row.registerCountReal +')'
                    }
                },

                {
                    field: 'registerRate',
                    title: '注册率',
                    formatter: function (value, row, index){
                        return row.registerCountReal == undefined?'<span style="color: red">'+row.registerRate+'</span>':'<span style="color: red">'+row.registerRate+ '('+ row.registerRateReal+')'+'</span>';
                    }
                },
                {
                    field: 'registerCountOff',
                    title: '注册数量(扣)',
                    formatter: function (value, row, index) {
                        if (row.channelRate == undefined){
                            return value;
                        }
                        return '(' + row.channelRate +')' + value;
                    }
                },
                {
                    field: 'registerCostOff',
                    title: '注册成本(扣)'
                },
                {
                    field: 'loginCount',
                    title: '登陆数量',
                    formatter: function (value,row,index){
                        var result = (row.channelCode == undefined)?row.loginCount:'<span style="color: #1c84c6; border-bottom: 1px solid" onclick="CountView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.loginCount+'</span>';
                        return result;
                    }
                },
                {
                    field: 'requestWechatCount',
                    title: '微信 / QQ',
                    formatter: function (value, row, index){
                        return row.requestWechatCount + ' / '+ row.requestQqCount;
                    }
                },
                // {
                //     field: 'requestQqCount',
                //     title: 'QQ来源数'
                // },
                    {
                        field: 'authCount',
                        title: '认证数量 / 优质量（率）',
                        formatter: function (value, row, index) {
                            var ratio = (row.authGoodCount / row.authCount) * 100;
                            return row.authCount + ' / ' + row.authGoodCount + ' (' + ratio.toFixed(2) + '%)';
                        }
                    },
                    {
                    field: 'authRate',
                    title: '认证率',
                    formatter: function (value, row, index){
                        return '<span style="color: red">'+row.authRate+'</span>'
                    }
                },
                {
                    field: 'downloadCount',
                    title: '下载数量'
                },
                {
                    field: 'downloadRate',
                    title: '下载率认证（注册）',
                    formatter: function (value, row, index){
                        return '<span style="color: red">'+row.downloadRateAuth+'</span>' + '（'+row.downloadRate+'）'
                    }
                },
                {
                    field: '',
                    title: '风控数据',
                    formatter: function (value, row, index){
                        return row.riskRequestNumber + ' / '+ row.riskSuccessNumber + ' / ' + row.riskSuccessRate
                    }
                },
                    {
                        field: '',
                        title: '线索量（成本）',
                        formatter: function (value, row, index){
                            return row.sourceCount+ '（'+row.sourceCost+'）'
                        }
                    },
                {
                    field: 'uvProdList',
                    title: 'uv列表'
                },
                {
                    field: 'proUvCount',
                    title: '下游uv数量',
                    formatter: function (value,row,index){
                        var result = (row.channelCode == undefined)?row.proUvCount:'<span style="color: #1c84c6; border-bottom: 1px solid" onclick="proUvCountView(\''+row.id+'\',\'' +row.channelName+'-'+row.dateInfo+'\')">'+row.proUvCount+'</span>';
                        return result;
                    }
                },
                {
                    field: 'uvTransRate',
                    title: 'uv转化率'
                },
                {
                    field: 'uvProduceRate',
                    title: 'uv产出率'
                },
                {
                    field: 'proUvProfit',
                    title: 'uv收益'
                },

                {
                    field: 'uvAvgProfit',
                    title: 'uv平均收益'
                },
                {
                    field: 'roiRate',
                    title: 'uvROI',
                    formatter: function (value, row, index){
                        return '<span style="color: red">'+row.roiRate+'</span>'
                    }
                },
                    {
                        field: 'spePushCount',
                        title: '机构推送量'
                    },
                    {
                        field: 'spePushAmount',
                        title: '机构收益'
                    },

                    {
                        field: 'formPushCount',
                        title: '表单推送量'
                    },
                    {
                        field: 'formPushAmount',
                        title: '表单收益'
                    },
                    {
                        field: 'pushRoiRate',
                        title: 'pushROI',
                        formatter: function (value, row, index){
                            return '<span style="color: red">'+row.pushRoiRate+'</span>'
                        }
                    },
                    {
                        field: 'ownerName',
                        title: '商务'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];

                            if (row.channelCode != undefined){
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            }
                            return actions.join('');
                        }
                    }

                ]
            };
            $.table.init(options);

            // 定时刷新
            setInterval(function(){ $.table.refresh("bootstrap-table", 1); }, 1000 * 60);

            window.uvCountView = function (id, title){
                var url = prefixView + "uvCountView/" + id;
                $.modal.open(title, url);
            }

        });

        $('#dateInfo').daterangepicker({
                "timePicker": false,
                "timePicker24Hour": false,
                "timePickerSeconds": false,
                "locale": {
                    "direction": "ltr",
                    "format": "YYYY-MM-DD",
                    "separator": " ~ ",
                    "applyLabel": "确定",
                    "cancelLabel": "取消",
                    "daysOfWeek": [ "七", "一", "二", "三", "四", "五", "六"],
                    "monthNames": ["1","2","3","4","5","6","7","8","9","10","11","12"
                    ],
                    // "firstDay": 1
                }
            },function (){}
        );

        function channelInfoView(id, title){
            var url = prefixView + "channelInfoView/" + id;
            $.modal.open(title, url);
        }


        function proUvCountView(id, title){
            var url = prefixView + "proUvCountView/" + id;
            $.modal.open(title, url);
        }

        function CountView(id, title){
            var url = prefixView + "CountView/" + id;
            $.modal.open(title, url);
        }

    </script>
</body>
</html>